package fl.android.ui;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

public class PianoRoll {
	private static final float[] wheights = new float[] { 1.5f, 2f, 1.5f, 1.5f,
			2f, 2f, 1.5f, 1f };
	private static final float[] bbottoms = new float[] { 1f, 3f, 6f, 8f, 10f };

	private ArrayList<PianoKey> whiteKeys = new ArrayList<PianoKey>();
	private ArrayList<PianoKey> blackKeys = new ArrayList<PianoKey>();

	public PianoRoll() {
		float y = 0f;
		float off = 1 / 1024f;
		for (int i = 0; i < wheights.length; i++) {
			float hei = wheights[i] / 13f * .9f;
			whiteKeys.add(new PianoKey(0f, y / 13f * .9f + off+.1f, .2f - off, hei - off
					* 2, true));
			y += wheights[i];
		}

		float bhei = 1f/13f - 2 * off;
		float bwid = .2f * 2f / 3f;
		for (int i = 0; i < bbottoms.length; i++) {
			y = bbottoms[i] / 13f * .9f;
			whiteKeys.add(new PianoKey(0f, y+.1f, bwid, bhei, false));
		}
	}

	public void render(GL10 gl) {
		for (PianoKey key : whiteKeys) {
			key.render(gl);
		}
		for (PianoKey key : blackKeys) {
			key.render(gl);
		}

	}

	public void touch(int tx, int ty) {

	}

	private class PianoKey {
		boolean white;
		float x, y, wid, hei;

		public PianoKey(float x, float y, float wid, float hei, boolean white) {
			this.x = x;
			this.y = y;
			this.wid = wid;
			this.hei = hei;
			this.white = white;
		}

		public void render(GL10 gl) {
			float cr = (white) ? 1f : 0f;
			Rect.render(gl, x, y, white ? .1f : .2f, wid, hei, new float[] {
					cr, cr, cr, 1f });
		}
	}
}
